package com.gome.axwl.aoc.service.impl;

import com.gome.axwl.aoc.entity.driver.TakesendTaskSpeech;
import com.gome.axwl.aoc.entity.po.QueryAllotTaskPo;
import com.gome.axwl.aoc.entity.po.TaskJobSearchPo;
import com.gome.axwl.aoc.entity.po.TruckListSearchPo;
import com.gome.axwl.aoc.service.TruckService;
import com.gome.axwl.aoc.service.feign.MasterDataFeignClient;
import com.gome.axwl.aoc.service.feign.TruckFeignClient;
import com.gome.common.utils.StringUtil;
import com.gome.commons.core.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("truckService")
public class TruckServiceImpl implements TruckService {

    @Autowired
    private MasterDataFeignClient masterDataFeignClient;

    @Autowired
    private TruckFeignClient truckFeignClient;

    /**
     * 模糊查询司机
     *
     * @param keyword
     * @return
     */
    @Override
    public Object getDriverByKeyword(String keyword, String dcId) {
        return masterDataFeignClient.QueryDriverByKeyword(keyword, dcId);
    }

    /**
     * 分页查询车次列表
     *
     * @param truckListSearchPo
     * @return
     */
    @Override
    public ResultData getTruckList(TruckListSearchPo truckListSearchPo) {
        if (StringUtil.isEmpty(truckListSearchPo.getDriver())) {
            truckListSearchPo.setDriver(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getOrderNo())) {
            truckListSearchPo.setOrderNo(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getTaskNo())) {
            truckListSearchPo.setTaskNo(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getCarrierId())) {
            truckListSearchPo.setCarrierId(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getStatus())) {
            truckListSearchPo.setStatus(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getTakesendNo())) {
            truckListSearchPo.setTakesendNo(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getVehicleNo())) {
            truckListSearchPo.setVehicleNo(null);
        }
        if (StringUtil.isEmpty(truckListSearchPo.getWaybillNo())) {
            truckListSearchPo.setWaybillNo(null);
        }
        return truckFeignClient.getTruckList(truckListSearchPo.getTakesendNo(), truckListSearchPo.getWaybillNo(), truckListSearchPo.getOrderNo(), truckListSearchPo.getTaskNo(), truckListSearchPo.getCarrierId(), truckListSearchPo.getDriver(), truckListSearchPo.getVehicleNo(), truckListSearchPo.getStatus(), truckListSearchPo.getAcceptDcIds(), truckListSearchPo.getPageNum(), truckListSearchPo.getPageSize());
    }

    /**
     * 分页查询任务单列表
     *
     * @param taskJobSearchPo
     * @return
     */
    @Override
    public ResultData getTaskJobList(TaskJobSearchPo taskJobSearchPo) {
        if (StringUtil.isEmpty(taskJobSearchPo.getStatus())) {
            taskJobSearchPo.setStatus(null);
        }
        if (StringUtil.isEmpty(taskJobSearchPo.getTaskNo())) {
            taskJobSearchPo.setTaskNo(null);
        }
        if (StringUtil.isEmpty(taskJobSearchPo.getWaybillNo())) {
            taskJobSearchPo.setWaybillNo(null);
        }
        return truckFeignClient.getTaskJobList(taskJobSearchPo.getTakesendId(), taskJobSearchPo.getTaskNo(), taskJobSearchPo.getWaybillNo(), taskJobSearchPo.getStatus(), taskJobSearchPo.getPageNum(), taskJobSearchPo.getPageSize());
    }

    /**
     * 下载评价文件
     *
     * @param taskNo
     */
    @Override
    public ResultData<List<TakesendTaskSpeech>> filesDownloadToZip(String taskNo) {
        return truckFeignClient.filesDownloadToZip(taskNo);
    }

    @Override
    public ResultData queryTakesendTask(QueryAllotTaskPo queryAllotTaskPo) {
        return truckFeignClient.queryTakesendTask(queryAllotTaskPo.getTasksendNo(), queryAllotTaskPo.getTakesendId(), queryAllotTaskPo.getTaskNo(), queryAllotTaskPo.getWaybillNo(), queryAllotTaskPo.getStatus(), queryAllotTaskPo.getPageNum(), queryAllotTaskPo.getPageSize());
    }

    @Override
    public ResultData queryTakesendDetail(long takesendId) {
        return truckFeignClient.queryTakesendDetail(takesendId);
    }
}
